<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <!--{include file='comm/header.tpl'}-->
    <title>商品标签组</title>
</head>

<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="ebsig_container">

    <!--{include file='comm/menu.tpl'}-->
    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td height="27px">
                                    <span>标签组名称：<input type="text"  name="tagGroupName" value="" /></span>
                                    <span><input type="button" value="查询" class="btn" onclick="tagGroup.search();" /></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>

<div id="pop" style="display: none;">
    <div style="width:100%; background: #ffffff">
        <form id = "tagGroup_form" onsubmit="return false;">
            <div class="input-group input-group-lg"  >
                <span class="input-group-addon">标签组名称：</span>
                <input class="form-control"  type="text" id="tagGroupName" name="tagGroupName" maxlength="20" placeholder="请输入标签组名称 【必填项】"  value="" />
            </div>

            <div class="input-group input-group-lg"  >
                <span class="input-group-addon">标签组别名：</span>
                <input class="form-control"  type="text" id="memoName" name="memoName" maxlength="20" placeholder="请输入标签组别名 【必填项】"  value="" />
            </div>

            <div class="input-group input-group-lg"  >
                <span class="input-group-addon">排列序号：</span>
                <input class="form-control"  type="text" id="sortOrder" name="sortOrder" maxlength="20" placeholder="请输入排列序号 【必填项】" />
            </div>
            <input type="hidden" name="useFlg" id="useFlg" value= "1" />
            <input type="hidden" name="tagGroupID" id="tagGroupID" value= "" />
        </form>
    </div>

</div>

<script type="text/javascript">
$("#flex").flexigrid({
    url:"/invokingAjax-backend/goods/tagGroup.ajax?operFlg=1&xjx=none",
        dataType: "json",
        colModel : [
        	<!--{if $edit_permission}-->
            {display: "操作", width : 100, align: "center"},
            <!--{/if}-->
            {display: "标签组名称", width : 150},
            {display: "标签组别名", width : 150},
            {display: "排列序号", width : 100,sortable : true,name : "sortOrder"},
            {display: "使用状态", width : 100 , align: "center"}
        ],
        <!--{if $edit_permission}-->
        buttons : [
            {name: "添加", bclass: "add", onpress : "tagGroup.edit"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "tagGroup.tagGroupDel"}
        ],
        <!--{/if}-->
        sortname: "sortOrder",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var tagGroup = {

        delete_str: "" ,
		useFlg_str : "" ,
		dt:"",
        //搜索标签组
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        tagGroupDel: function() {
            this.delete_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    tagGroup.delete_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.delete_str == "")
                E.alert("请选择需要删除的商品标签组");
            else
                E.confirm("删除商品标签组会同步删除商品标签组下面的标签，您确认删除吗？", "tagGroup.deleteConfirm");
        },
        
		doAction: function( tagGroupID , useFlg ) {
            this.useFlg_str = tagGroupID + "_" + useFlg ;
            if( useFlg == 0 )
            	E.confirm("您确认要禁用此商品标签组吗？", "tagGroup.actionConfirm");
            else
            	tagGroup.actionConfirm() ;
        },
        
        actionConfirm : function () {
        	E.loadding.open('请稍后...');
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/tagGroup.ajax?operFlg=5&useFlg_str=" + tagGroup.useFlg_str,
                dataType: "JSON",
                success: function( result_obj ) {
                	E.loadding.close();
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "tagGroup.load");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },
        
        deleteConfirm: function() {
            this.delete_str = this.delete_str.substr(1);
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/tagGroup.ajax?operFlg=4&delete_str=" + tagGroup.delete_str,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "tagGroup.load");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        edit: function(tagGroupID) {
            var name="";
            E.loadding.open("请稍等...");
            if(tagGroupID){
                name = "修改商品标签组";
                E.ajax_post({
                    url: "/invokingAjax-backend/goods/tagGroup.ajax?operFlg=6",
                    data:{tagGroupID:tagGroupID},
                    call:"tagGroup.tagGroupEdit"
                });
                
            }else{
                name = "添加商品标签组";
                E.ajax_post({
                    url:"/invokingAjax-backend/goods/tagGroup.ajax?operFlg=7" ,
                    call:"tagGroup.resort"
                });
                
            }
            E.popup.open({
                id: "pop",
                title: name,
                css: "width:960px;",
                btnName: "保存",
                btnCall:"tagGroup.check();"
            });
        },

        //编辑弹出框赋值
        tagGroupEdit:function(o){
            E.loadding.close();
            if(o == null){
                E.alert('没有找到信息');
                return false;
            }
            $("#tagGroupName").val(o.tagGroupName);
            $("#memoName").val(o.memoName);
            $("#useFlg").val(o.useFlg);
            $("#sortOrder").val(o.sortOrder);
            $("#tagGroupID").val(o.tagGroupID);
        },

        check: function() {

            this.dt = E.getFormValues("tagGroup_form");
            var error_msg = "";

            if (this.dt.tagGroupName == "")
                error_msg += "标签组名称不能为空<br />";

            if (this.dt.memoName == "")
                error_msg += "标签组别名不能为空<br />";

            if (!E.isInt(this.dt.sortOrder))
                error_msg += "排序序号必须为数字<br />";

            if (error_msg != "")
                E.alert(error_msg);
            else
                tagGroup.addSave() ;
        },

        //保存标签组信息
        addSave: function() {
            this.dt        = E.getFormValues("tagGroup_form");
            var sortOrder  = this.dt.sortOrder;
            sortOrder++;
            var tagGroupID = this.dt.tagGroupID;
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/tagGroup.ajax?operFlg=2" ,
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        tagGroup.load();
                        if(tagGroupID){
                            E.alert(result_obj.message, 2, "E.popup.close");
                        }else{
                            E.alert(result_obj.message, 2);

                            $("#tagGroupName").val('');
                            $("#memoName").val('');
                            $("input[name='useFlg'][value='1']").attr("checked",true);
                            $("#sortOrder").val(sortOrder);
                        }
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },
        //最大序列号重置
        resort: function(o){
        	E.loadding.close();
            $("#sortOrder").val(o.sortOrder);
        },
        load: function() {
            $("#flex").flexReload();
        }

    };
</script>

</body>

</html>
